<template>
    <jb-crud-page
        ref="pageRef"
        title-icon="icon-park-outline:log"
        title-text="登录日志"
        search-url="/api/admin/loginLog/datas"
        :search-conditions="pageConditions"
    >
        <template #conditions-form>
            <n-input
                v-model:value="pageConditions.keywords"
                type="text"
                placeholder="请输入关键字搜索"
            />
            <jb-date-range
                v-model:value="pageConditions.dateRange"
                format-pattern="yyyy-MM-dd"
            ></jb-date-range>
        </template>
        <template #opt>
            <jb-btn
                :icon="Icons.REFRESH"
                ghost
                type="primary"
                @click="pageRef?.loadData()"
            >
                刷新
            </jb-btn>
        </template>

        <template #default="{ state }">
            <vxe-table
                border
                :column-config="{ resizable: true }"
                height="auto"
                show-header-overflow
                show-overflow="tooltip"
                :seq-config="{ startIndex: state.tableStartIndex }"
                :row-config="{ isHover: true }"
                align="center"
                :data="state.list"
            >
                >
                <jb-column type="seq" title="序号" width="60" fixed="left"></jb-column>
                <jb-column
                    field="username"
                    title="用户名（id）"
                    min-width="140"
                    fixed="left"
                ></jb-column>
                <jb-column title="登录状态" min-width="140" fixed="left">
                    <template #default="{ row }">
                        {{ row?.loginState == '1' ? '登陆成功' : '验证码输入错误' }}
                    </template>
                </jb-column>
                <jb-column field="remote" title="异地登录" min-width="140">
                    <template #default="{ row }">
                        {{ row?.isRemoteLogin ? '是' : '否' }}
                    </template>
                </jb-column>

                <jb-column field="loginTime" title="登录时间" min-width="200"></jb-column>
                <jb-column field="osName" title="操作系统" min-width="200"></jb-column>
                <jb-column field="browserName" title="浏览器" min-width="200"></jb-column>
                <jb-column field="loginIp" title="登录IP" min-width="200"></jb-column>
                <jb-column
                    field="loginAddress"
                    title="登录地址"
                    min-width="200"
                ></jb-column>
                <jb-column title="操作" min-width="120" fixed="right">
                    <template #default="{ row }">
                        <jb-btn
                            :icon="Icons.EYE"
                            type="primary"
                            ghost
                            tip-text="登录日志详情查看"
                            :drawer-component="LoginLog"
                            :drawer-title="`查看${row?.username}登录日志详情`"
                            :drawer-component-props="{ id: row.id }"
                            :drawer-positive-text="''"
                            >查看</jb-btn
                        >
                    </template>
                </jb-column>
            </vxe-table>
        </template>
    </jb-crud-page>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { Icons } from '@/constants'
import JbCrudPage from '@/components/_builtin/jb-crud-page/index.vue'
import LoginLog from '@/views/_builtin/monitor/onlineuser/component/login-log.vue'
import { useResetableData } from '@/hooks/common/use-resetable-data'

const pageRef = ref<InstanceType<typeof JbCrudPage> | null>(null)
const pageConditions = useResetableData({
    keywords: '',
    dateRange: ''
})
</script>

<style scoped></style>
